package it.progettoso.thread;

import android.content.Context;
import android.media.AudioManager;
import android.telephony.TelephonyManager;
import android.telephony.SmsManager;

public class InfoSmartPhoneThread implements Runnable{

	private TelephonyManager telephonyManager;
	private String mess,phone,callState,dataState,batteryLevel;
	private Context c=null;
	AudioManager manager=null;
	
	public InfoSmartPhoneThread(String phone,Context context,String batteryLevel) {
		this.phone=phone;
		this.c=context;
		this.batteryLevel=batteryLevel;
		mess= "INFOSMARTPHONE:";
		this.telephonyManager=(TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);	
	}
	@Override
	public void run() {
		
		getStateInfo();
		
		mess=mess+ "Stato chiamate:"+ callState+ "*Connessione dati:"+ dataState +
		"*ID Dispositivo:"+telephonyManager.getDeviceId() +	"*Stato Batteria:"+batteryLevel +"*";

		sendSMS(phone, mess);

	}

	private void getStateInfo() {
		switch (telephonyManager.getCallState()) {
		case TelephonyManager.CALL_STATE_IDLE:
			this.callState="No activity";
			break;
		case TelephonyManager.CALL_STATE_OFFHOOK:
			this.callState="OFFHOOK";
			break;
		case TelephonyManager.CALL_STATE_RINGING:
			this.callState="Ringing";
			break;
		default:
			break;
		}

		switch (telephonyManager.getDataState()) {
		case TelephonyManager.DATA_CONNECTED:
			dataState="Connected";
			break;
		case TelephonyManager.DATA_CONNECTING:
			dataState="Connecting";
			break;		
		case TelephonyManager.DATA_DISCONNECTED:
			dataState="Disconnected";
			break;		
		case TelephonyManager.DATA_SUSPENDED:
			dataState="Suspended";
			break;
		default:
			break;
		}
	}

	//---sends a SMS message to another device---
	public void sendSMS(String phoneNumber, String message){      
		SmsManager sms = SmsManager.getDefault();
		sms.sendTextMessage(phoneNumber, null, message, null, null);               
	}  
}
